#pragma once
#include<iostream>
#include<pthread.h>
using std::cout;
using std::endl;

class myMutex{
    public:
        myMutex(){
            pthread_mutex_init(&_lock,nullptr);
        }
        void lock()
        {
            pthread_mutex_lock(&_lock);
        }
        void unlock()
        {
            pthread_mutex_unlock(&_lock);
        }
        ~myMutex()
        {
            pthread_mutex_destroy(&_lock);
        }
    private:
        pthread_mutex_t _lock;
};

class LockGuard
{
    public:
        LockGuard(myMutex* myMutex)
            :_myMutex(myMutex){
                _myMutex->lock();
                cout<<"Locked!"<<endl;
            }
        ~LockGuard()
        {
            _myMutex->unlock();
            cout<<"Unlocked!"<<endl;
        }
    private:
        myMutex* _myMutex;
};
